from models.models_dev import OpOrder as DevOpOrder
from models.models_prod import OpOrder as ProdOpOrder
from services.base_dev_common_service import BaseDevCommonService
from utils.obj_utils import ObjectUtil


class DevOrderService(BaseDevCommonService):
    def __init__(self):
        super().__init__(model_class=DevOpOrder, time_field='created_time')

    def add(self, prod_orders: list[ProdOpOrder],session=None):
        # 如果未提供session，则获取新的session
        if session is None:
            session = self.get_session()
        dev_orders = []
        for prod_order in prod_orders:
            dev_order = DevOpOrder()
            ObjectUtil.copy_fields(dev_order, prod_order, self.get_table_fields({'id'}))
            dev_orders.append(dev_order)
        session.add_all(dev_orders)
        session.commit()
